
<#if !function.readonly?? || function.readonly=="0">
	<#if child_group_list??>
	<#list child_group_list as item>
	

        		<input type="hidden" id="${list.businessObj.name}id"/>
     
            	<#if item.group?? && (!item.group.isShowTitle?? || item.group.isShowTitle=='1')>
         
              <span style="margin-left:10px;">${item.group.name}</span>
            
                </#if>
            ${item.content?replace('listviewTR','listviewTR subForm')}
           
     
      
       </#list>
       </#if>

  
<#if (child_function_list?? && child_function_list?size gt 0) || (child_common_func_list?? && child_common_func_list?size gt 0)>
   
<tr class="listviewTR"><td class="listviewTD" ></td><td class="listviewTD" colSpan="5">
    
            <#list child_function_list as func>
                <#assign show="0">
                <#list feature_list as feature>
                    <#if func.function.name==feature.code>
                        <#if businessInstance.procDefId?? && businessInstance.status??>
                            <#if func.procDefId?? && func.status?? && func.procDefId==businessInstance.procDefId && func.status==businessInstance.status.id>
                                <#assign show="1">
                            </#if>
                        <#else>
                            <#assign show="1">
                        </#if>
                    </#if>
                </#list>    
                <#if show?? && show=="1">
                <a href="#" class="button" tabindex="-1">
                <input id="btn${func.function.name}" type="button"  class="button" value="<#if func.function?? && func.function.displayName??>${func.function.displayName}</#if>" onclick="save${list.businessObj.name}('${func.function.id}','<#if func.function?? && func.function.type??>${func.function.type}</#if>',<#if func.function.messageType??>'${func.function.messageType}'<#else>'0'</#if>,<#if func.function.message??>'${func.function.message}'<#else>''</#if>)"/>&nbsp;&nbsp;
                </a>
                </#if>
             </#list>
             
             <#if child_common_func_list??>
             <#list child_common_func_list as func>
                <#assign show="0">
                <#list feature_list as feature>
                    <#if func.function.name==feature.code>
                        <#assign show="1">
                    </#if>
                </#list>    
                <#if show?? && show=="1">
                <a href="#" class="button" tabindex="-1">
                <input id="btn${func.function.name}" type="button"  class="button" value="<#if func.function?? && func.function.displayName??>${func.function.displayName}</#if>" onclick="save${list.businessObj.name}('${func.function.id}','<#if func.function?? && func.function.type??>${func.function.type}</#if>',<#if func.function.messageType??>'${func.function.messageType}'<#else>'0'</#if>,<#if func.function.message??>'${func.function.message}'<#else>''</#if>)"/>&nbsp;&nbsp;
                </a>
                </#if>
             </#list>
             </#if>
    
   
        </td></tr>
        </#if> 

       
</#if>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td>
<div id="${list.businessObj.name}">
	<table tabletype="datagrid" field="${list.businessObj.name}" id="GridTable${list.businessObj.name}"></table>
</div>
</td>
</tr>
</table>

<script language="javascript">
// JavaScript Document
var validator${list.businessObj.name};
var load${list.businessObj.name}=false;
$(function(){
    //gotoGrid${list.businessObj.name}();
		$('.subForm').each(function(){
  		$(this).find("input").each(function(){
	  		$(this).attr("valid","false");
  		});
  	});
  	$('.subForm').each(function(){
  		$(this).find("select").each(function(){
  		$(this).attr("valid","false");
  		});
  	});
  	$('.subForm').each(function(){
  		$(this).find("textarea").each(function(){
  		$(this).attr("valid","false");
  		});
  	});
});
$(window).resize(function(){resizeDatagrid();})
function gotoGrid${list.businessObj.name}(){
	if(!load${list.businessObj.name}) {
		loadGrid${list.businessObj.name}();
			var view1Height = $("#GridTable${list.businessObj.name}").parent(".datagrid-view").find(".datagrid-header",".datagrid-view1").height();
		if(view1Height == 0){
			window.setTimeout("gotoGrid${list.businessObj.name}()",0);
		}else{
			load${list.businessObj.name}=true;
			window.clearTimeout("gotoGrid${list.businessObj.name}()");
		}
	}
}

 function formSerialize${list.businessObj.name}(formDivId) {
  	var serializeData = '';
  	$('#form1 .subForm').each(function(){
  		$(this).find("input").each(function(){
	  		if(this.type=='checkbox') {
	  			if(this.checked) {
	  				$(this).val('on');
	  			} else {
	  				$(this).val('off');
	  			}
	  		}
	  		var data = '&' + $(this).attr("name") + '=' + encodeURI($(this).val());
	  		serializeData += data;
  		});
  	});
  	$('#form1 .subForm').each(function(){
  		$(this).find("select").each(function(){
  		var data = '&' + $(this).attr("name") + '=' + $(this).val();
  		serializeData += data;
  		});
  	});
  	$('#form1 .subForm').each(function(){
  		$(this).find("textarea").each(function(){
  		var value = $(this).text();
  		if(!value || value=='') {
  			value = $(this).val();
  		}
  		var data = '&' + $(this).attr("name") + '=' + encodeURI(value);
  		serializeData += data;
  		});
  	});
  	return serializeData;
  }
  function clear${list.businessObj.name}(formDivId) {
  	$('.subForm').find("input").each(function(){
  		if(this.type=='text') {
  			$(this).val('');
  		}
  		if(this.type=='checkbox') {
  			$(this).removeAttr("checked");
  		}
  	});
  	$('.subForm').find("textarea").each(function(){
  		$(this).val('');
  		$(this).text('');
  	});
  	$('#${list.businessObj.name}id').val('');
  }
function validateForm${list.businessObj.name}() {
	var ${list.businessObj.name}Form = document.createElement('form');
	var table = document.createElement('table');
	//$(table).html($(document.getElementById('${list.businessObj.name}Table')).html());
	$('.subForm').each(function(){
		$(table).append($(this).clone());
	});
	$(${list.businessObj.name}Form).append(table);
	var form1 = document.getElementById('form1');
	$("input",${list.businessObj.name}Form).each(function(){
		if(this.type=="checkbox") {
			if($('input[name="'+this.name+'"]',form1)[0].checked) {
				$(this).attr('checked','checked');
			}
		} else if(this.type=="textarea") {
			$(this).attr('text',$($('input[name="'+this.name+'"]',form1)[0]).attr('text'));
		} else {
			$(this).val($($('input[name="'+this.name+'"]',form1)[0]).val());
		}
	});
	validator${list.businessObj.name} = $(${list.businessObj.name}Form).validate( {
			submitHandler : function(form) {
				
			},
			errorContainer : $('div.container'),
			errorLabelContainer : $("ol", 'div.container'),
			wrapper : 'li',
			meta : "validate",
			focusInvalid : false,
			rules : {},
			messages : {}
		});
		var strtextAreas${list.businessObj.name} = $("textarea[datarule='string']",${list.businessObj.name}Form);
			strtextAreas${list.businessObj.name}.each(function(i) {
				var jsonStr = $(this).attr("datarulejson");
				var rule = $.parseJSON(jsonStr);
				var optionRule = {};
				var optionRuleMessages = {};
				jQuery.validator.methods.Required(rule,optionRule,optionRuleMessages);
				if (rule.length != null) {
					optionRule["maxlength"] = rule.length;
					optionRuleMessages["maxlength"] = rule.displayName
							+ "最大不能超过" + rule.length + "个字符！";
				}
				optionRule["messages"] = optionRuleMessages;
				$(this).rules("add", optionRule);
			});

			var strInputs${list.businessObj.name} = $("input[datarule='string']",${list.businessObj.name}Form);
			strInputs${list.businessObj.name}.each(function(i) {
				var jsonStr = $(this).attr("datarulejson");
				var rule = $.parseJSON(jsonStr);
				var optionRule = {};
				var optionRuleMessages = {};
				jQuery.validator.methods.Required(rule,optionRule,optionRuleMessages);
				if (rule.length != null) {
					optionRule["maxlength"] = rule.length;
					optionRuleMessages["maxlength"] = rule.displayName
							+ "最大不能超过" + rule.length + "个字符！";
				}
				optionRule["messages"] = optionRuleMessages;
				$(this).rules("add", optionRule);
			});

			var yearInputs${list.businessObj.name} = $("input[datarule='year']",${list.businessObj.name}Form);
			yearInputs${list.businessObj.name}.each(function(i) {
				var jsonStr = $(this).attr("datarulejson");
				var rule = $.parseJSON(jsonStr);
				var optionRule = {};
				var optionRuleMessages = {};
				jQuery.validator.methods.Required(rule,optionRule,optionRuleMessages);
				optionRule["checkyear"] = "#checkyear";
				optionRuleMessages["checkyear"] = jQuery.validator.methods
						.checkyearmessage(rule);
				optionRule["messages"] = optionRuleMessages;
				$(this).rules("add", optionRule);
			});

			var numberInputs${list.businessObj.name} = $("input[datarule='number']",${list.businessObj.name}Form);
			numberInputs${list.businessObj.name}.each(function(i) {
				var jsonStr = $(this).attr("datarulejson");
				var rule = $.parseJSON(jsonStr);
				var optionRule = {};
				var optionRuleMessages = {};
				jQuery.validator.methods.Required(rule,optionRule,optionRuleMessages);
				optionRule["checknumber"] = "#checknumber";
				optionRuleMessages["checknumber"] = jQuery.validator.methods
						.checknumbermessage(rule);

				optionRule["messages"] = optionRuleMessages;
				$(this).rules("add", optionRule);
			});
			
			var regexInputs = $("input[datarule='regex']",${list.businessObj.name}Form);
			regexInputs.each(function(i) {
				var jsonStr = $(this).attr("datarulejson");
				var rule = $.parseJSON(jsonStr);
				var optionRule = {};
				var optionRuleMessages = {};
				jQuery.validator.methods.Required(rule,optionRule,optionRuleMessages);
				jQuery.validator.methods.IgnoreValidate(rule,$(this));	

				optionRule["checkregex"] = "#checkregex";
				optionRuleMessages["checkregex"] = rule.displayName +rule.message;
				
				optionRule["messages"] = optionRuleMessages;
				$(this).rules("add", optionRule);				
			});
			
			if(!validator${list.businessObj.name}.form()) {
     		return false;
  		}
  		return true;
}
function save${list.businessObj.name}(funcId,messageType,message,forwardType) {
	if(!validateForm${list.businessObj.name}()) {
     return false;
  }
	process${list.businessObj.name}(funcId,messageType,message,forwardType);
}

function process${list.businessObj.name}(funcId,messageType,message,forwardType) {
      ${"$('#functionId')"}.val(funcId);
      var url = TDQS.CONTEXT_PATH+'business/process?tdqssid='+TDQS.SESSION_ID+ "&function.id="+funcId+"&businessProcess.id=${businessProcess.id}&list.id=${list.id}&businessInstance.parentInstance.id=${businessInstance.id}&fieldMap['businessInstance.parentInstance.id'].value=${businessInstance.id}"+formSerialize${list.businessObj.name}('${list.businessObj.name}Table');
      if($('#${list.businessObj.name}id').val()!='') {
          url += ("&id="+$('#${list.businessObj.name}id').val());
      }
      url += "&date="+new Date().toLocaleString();
      if(!message||message=='') {
            message = '确定要执行操作吗？';
      }
      if(messageType && messageType=='1') {
          jConfirm(message, '确认对话框 ', function(r) {
                        if(r){
                            if(forwardType && forwardType=='2') {
                                executeAjaxFunction${list.businessObj.name}(url);
                            }
                        }else{
                            return false;
                        }
          });
      }
      else {
            executeAjaxFunction${list.businessObj.name}(url);
      }
}




function option${list.businessObj.name}() {

	this.executeAjaxFunctionsuccess = function(json) { 

	};

}
var   objoption${list.businessObj.name} = new option${list.businessObj.name}();
function executeAjaxFunction${list.businessObj.name}(url) {
    $.tdqsAjax({
        type: "post",
        dataType: "json",
        url: url,
        success:function(json) {
            if(json.data && json.data.type && json.data.type=='2' && json.data.resultData){
                jAlert(json.data.resultData,'提示',function(){
                    $('#GridTable${list.businessObj.name}').datagrid("tdqsReload");
                    clear${list.businessObj.name}('${list.businessObj.name}Table');
                });
            }
            else {
                $('#GridTable${list.businessObj.name}').datagrid("tdqsReload");
                clear${list.businessObj.name}('${list.businessObj.name}Table');
            }

	    objoption${list.businessObj.name}.executeAjaxFunctionsuccess(json);

        }
    });
}

function processRowFunc${list.businessObj.name}(id,funcId,status,messageType,message,forwardType) {
     $('#${list.businessObj.name}id').val(id);
     process${list.businessObj.name}(funcId,messageType,message,forwardType);
}

function loadGrid${list.businessObj.name}(){
     $('#GridTable${list.businessObj.name}').datagrid({            
            url:TDQS.CONTEXT_PATH+'business/list.action?tdqssid='+TDQS.SESSION_ID+'&ajaxLoadType=1&list.id=${list.id}&businessProcess.id=${businessProcess.id}<#if businessInstance?? && businessInstance.id??>&parentInstance.id=${businessInstance.id}</#if>',
            idField:"id",
            pageNumber:1,
            pageSize:10,
            sortName: "<#if sort??>${sort}</#if>",
            sortOrder: "<#if order??>${order}</#if>",
            width: 'auto',
			height: 'auto',
			forminlist: "forminlist",
			onLoadSuccess:function(){resizeDatagrid();},
            frozenColumns:[[{
                 field : 'indexer',
                 title : '序号',
                 width : 50,
                 formatter:${"$"}.fn.datagrid.defaults.indexFormatter,
                 edit : false,
                 align : 'center',
                 defaultValue : ''
                }
                <#list listFields as listField>
                <#if listField.frozen?? && listField.frozen=='1'>
                ,{
                 field : '${listField.field.name}',
                 title : '${listField.title}',
                 width : ${listField.width},
                 editor : 'text',
                 defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                 align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                 edit : true,
                 formatter:function(value, row, index){
                     var fieldValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                         fieldValue = row.fieldMap['${listField.field.name}'].value;
                     }
                     var displayValue = '';
                     if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                         displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                     }
                     if(displayValue && displayValue!=null && displayValue!='') {
                         return displayValue;
                     }
                     if(fieldValue=='') {
                         fieldValue = '&nbsp;';
                     }
                     if(row.editStatusFunction && row.editStatusFunction.id) {
                          var value = "<a href=\"javascript:void(0);\" onclick=\"processRowFunc('"+row.id+"','"+row.editStatusFunction.id+"');return false;\">"+fieldValue+"</a>";
                         return value;
                     }
                     return fieldValue;
                 }
                } 
                </#if>
                </#list>
                ] ],
            columns:[ [ 
                <#assign index=0>
                <#list listFields as listField>
                <#if !listField.frozen?? || listField.frozen=='0'>
                <#if index gt 0>
                ,
                </#if>
                {
                    field : '${listField.field.name}',
                     title : '${listField.title}',
                     width : ${listField.width},
                     editor : 'text',
                     defaultValue : <#if listField.defaultValue??>'${listField.defaultValue}'<#else>''</#if>,
                     align : <#if listField.align??>'${listField.align}'<#else>'center'</#if>,
                     edit : true,
                     sortable : <#if listField?? && listField.sortable?? && listField.sortable=="1">true<#else>false</#if>,
                     formatter:function(value, row, index){
                          var fieldValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].value) {
                             fieldValue = row.fieldMap['${listField.field.name}'].value;
                         }
                         var displayValue = '';
                         if(row.fieldMap['${listField.field.name}'] && row.fieldMap['${listField.field.name}'].displayValue) {
                             displayValue = row.fieldMap['${listField.field.name}'].displayValue;
                         }
                         if(displayValue && displayValue!=null && displayValue!='') {
                             return displayValue;
                         }
                         if(fieldValue=='') {
                             fieldValue = '&nbsp;';
                         }
                         return fieldValue;
                     }
                }
                <#assign index=index+1>
                </#if>
                </#list>
                <#if list.allowOperColumn?? && list.allowOperColumn=="1">
                ,            
                 {    
                    field : 'opt',
                    title : '操作',
                    width : 100,
                    align : 'center',
                    rowspan : 1,
                    formatter:function(value, row, index){
                        var opers = '';
                        <#if !function.readonly?? || function.readonly=="0">
                        if(row && row.listFunctionList) {
                        	var status = '';
                        	if(row.status && row.status.id) {
                        		status = row.status.id;
                        	}
                            for(var i=0,l=row.listFunctionList.length;i<l;i++) {
                                 var func = row.listFunctionList[i];
                                 var funcId = '';
                                 var messageType = '';
                                 var message = '';
                                 var funcName = '';
                                 var forwardType = '';
                                 if(func) {
                                     if(func.id) {
                                         funcId = func.id;
                                     }
                                     if(func.messageType) {
                                         messageType = func.messageType;
                                     }
                                     if(func.message) {
                                         message = func.message;
                                     }
                                     if(func.displayName) {
                                         funcName = func.displayName;
                                     }
                                     else if(func.desc) {
                                         funcName = func.desc;
                                     }
                                     if(func.forwardType) {
                                         forwardType = func.forwardType;
                                     }
                                 }
                                 opers += "<a href=\"javascript:void(0)\" onclick=\"javascript:processRowFunc${list.businessObj.name}('"+row.id+"','"+funcId+"','"+status+"','"+messageType+"','"+message+"','"+forwardType+"');return false;\">"+funcName+"</a>";
                                 opers += "&nbsp;&nbsp;";
                            }
                        }
                        </#if>
                        if(opers=='') {
                             opers = '&nbsp;';
                        }
                        return opers; 
                    }
                }
                </#if>
                ] ],
            operations:{}
        });
            
}

function resizeDatagrid(){
		if($.data($('#GridTable${list.businessObj.name}'),"datagrid")) {
    	$('#GridTable${list.businessObj.name}').datagrid("autoresize",{innerGrid:"innergrid"});
    }
}

</script>
                                                                                                                                                                                                                                                                                    